const txtEl = document.querySelector(".txt");
const ulEl = document.querySelector(".todo-list");

txtEl.addEventListener("keydown", function (e) {
  if (e.key === "Enter") {
    if (!this.value.trim()) return;
    const li = document.createElement("li");

    li.innerHTML = `<span>${this.value}</span><button>删除</button>`;
    ulEl.appendChild(li);
    this.value = "";
  }
});

ulEl.addEventListener("click", function (e) {
  const target = e.target;
  if (target.tagName === "BUTTON") {
    target.parentNode.remove();
  }
});
